package com.yuandian.management.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuandian.api.management.entity.ConfProbeDataFilter;
import com.yuandian.api.management.validate.InsertFlag;
import com.yuandian.api.management.validate.UpdateFlag;
import com.yuandian.bpm.common.core.util.R;
import com.yuandian.bpm.common.log.annotation.SysLog;
import com.yuandian.management.service.ConfProbeDataFilterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 探针数据过滤表-Controller
 * @author zfsn
 * @date 2023-4-10
 */
@Api(tags = "原始数据包分析-抓包规则配置")
@RestController
@RequestMapping("/probeDataFilter")
public class ConfProbeDataFilterController {

	@Autowired
	private ConfProbeDataFilterService confProbeDataFilterService;

	/**
	 * 通过主键查询数据
	 * @param idList 主键集合
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "通过主键查询数据", notes = "通过主键查询数据，支持批量查询")
	@GetMapping("/{ids}")
	public R<List<ConfProbeDataFilter>> queryByIds(@PathVariable("ids") List<Integer> idList) {
		return R.ok(confProbeDataFilterService.listByIds(idList));
	}

	/**
	 * 分页查询
	 * @param confProbeDataFilter 筛选条件
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "分页查询", notes = "分页查询")
	@PostMapping
	public R<Page<ConfProbeDataFilter>> listPage(@RequestBody ConfProbeDataFilter confProbeDataFilter) {
		return R.ok(confProbeDataFilterService.listPage(confProbeDataFilter));
	}

	/**
	 * 新增数据
	 * @param confProbeDataFilter 实例对象
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "新增数据", notes = "新增数据")
	@SysLog("新增探针数据过滤表数据")
	@PostMapping("/save")
	public R<Boolean> save(@Validated({InsertFlag.class}) @RequestBody ConfProbeDataFilter confProbeDataFilter) {
		return R.ok(confProbeDataFilterService.save(confProbeDataFilter));
	}

	/**
	 * 通过主键更新数据
	 * @param confProbeDataFilter 实例对象
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "通过主键更新数据", notes = "通过主键更新数据")
	@SysLog("更新探针数据过滤表数据")
	@PutMapping
	public R<Boolean> updateById(@Validated({UpdateFlag.class}) @RequestBody ConfProbeDataFilter confProbeDataFilter) {
		return R.ok(confProbeDataFilterService.updateById(confProbeDataFilter));
	}

	/**
	 * 通过主键删除数据
	 * @param ids 主键
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "通过主键删除数据", notes = "通过主键删除数据")
	@SysLog("删除探针数据过滤表数据")
	@DeleteMapping("/delete/{ids}")
	public R<Boolean> removeByIds(@PathVariable("ids") List<Integer> ids){
		return R.ok(confProbeDataFilterService.removeByIds(ids));
	}

	/**
	 * 向探针同步过滤信息
	 *
	 * @param confProbeDataFilter 参数
	 * @return Result
	 */
	@PostMapping("/startSynFilterData")
	public R startSynFilterData(@RequestBody ConfProbeDataFilter confProbeDataFilter) {
		return confProbeDataFilterService.startSynFilterData(confProbeDataFilter);
	}

	/**
	 *
	 * 停止抓包
	 * @param ids id集
	 * @return Result
	 */
	@DeleteMapping("/stop/{ids}")
	public R stop(@PathVariable("ids") List<Integer> ids) {
		return confProbeDataFilterService.stop(ids);
	}
}